<style lang="scss" scoped>
  .form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .el-form-item {
      width: 250px;
    }
  }
</style>
<template>
  <el-dialog :title="title" :visible.sync="addDialogVisible" width="30%">
    <div class="ui-box leave_dialog">
      <el-form :model="roleItem" label-width="80px" :rules="formRule" ref="formRole" class="form">
        <el-form-item label="名称" prop="name">
          <el-input v-model="roleItem.name" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="roleItem.description" size="mini"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submit" size="mini">确 定</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
  export default {
    name: 'addItem',
    props: {
      roleItem: {
        name: '',
        description: ''
      }
    },
    data() {
      return {
        formRule: {
          name: [{required: true, message: '请输入名称', trigger: 'blur'}],
          description: [{required: true, message: '请输入描述', trigger: 'blur'}],
        },
        addDialogVisible: false,
        title: '',
      }
    },
    methods: {
      submit() {
        this.$refs['formRole'].validate((val) => {
          if (val) {
            this.$emit('submit')
          }
        })
      },
      openWindow(value) {
        // console.log('title',value);
        this.addDialogVisible = true;
        this.title = value;
        this.roleItem.name = ''
        this.roleItem.description = ''
      }
    }
  }
</script>

